package com.yeqian.user.handle;

import com.yeqian.entity.ResultJson;
import com.yeqian.system.mapper.SystemConfigMapper;
import com.yeqian.system.service.TaskTimeService;
import com.yeqian.user.entity.LoginConstant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.logout.LogoutSuccessHandler;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author yeqian
 * @Classname myLogoutSuccessHandler
 * @Description TODO 注销成功处理器
 * @Date 2021/5/8 14:51
 */
@Component
public class YeqLogoutSuccessHandler implements LogoutSuccessHandler {

    @Autowired
    private TaskTimeService taskTimeService;
    @Autowired
    private SystemConfigMapper systemConfigMapper;

    @Override
    public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException {

        taskTimeService.deleteQuartz(systemConfigMapper.selectById("bd192005-dbd7-11ec-bc2a-00ff3acdb0bc"));
        ResultJson.writeJSON(response, ResultJson.Success(LoginConstant.LOGOUT_SUCCEEDED));
    }
}
